home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1994
/
MacHack 1994.toast
/
MacHack™94
/
Talks & Papers
/
Timothy Knox
/
yerk 3.66
/
System source
/
Proc
< prev
next >
Wrap
Text File
|
1994-06-24
|
4KB
|
107 lines
\ A pair of words designed to enable Yerk words to be called with a
\ Pascal lookalike stack. Useful when a routine is passed to a Tool-
\ box entry for asynchronous routines.
\ Terminology: Any such Pascal lookalike is called a proc word
\ 10/15/84 RW
\ 12/22/85 CBD Rewrote PSTART, (Hyperdrive fix)
\ 8/31/88 rfl took out meaningless nop in pstart
\ 4/01/90 rfl took out adda.l #$48,a3 since no longer have old yerk header
\ 12/30/90 rfl stack now 3000, and 300 for method stack
\ 6/07/91 rfl yerk base now 2c from a5
\ 10/26/91 rfl increased stack to 7000 for use with system 7
\ 4/11/92 rfl flush cache on :proc if necessary
\ 5/02/92 rfl changed the way a5,a3 are recovered..stored at startup
\ in a resource called MYA5.
\ 4/24/93 rfl once again, changed the way a5,a3 are recovered. The resource
\ method moves memory and you don't want that if it is
\ called by interrupt. So now, to be safe, all procwords
\ defined in your application will be inited with a5,a3 at
\ startup time by sticking 'initProcs' into your startup word.
\ 5/18/93 rfl protected initproc from an assembly proc
\ 1/2/94 rfl reset stacks to larger values in proc
Hex
0 value pstartLen
\ PSTART - Converts Pascal stack format to our Forth stack format.
\ N.B. - VERY IMPORTANT!!! - This word will never be
\ directly executed. Instead the code will be CMOVE'd
\ into place during the execution of PROC and executed by
\ the routine active via JSR.
Create Pstart <[
600c w, \ bra.s next \ jump over data area
'type proc , \ \ marker to identify it as proc
0 , \ data \ a5 will be here
0 , \ \ a3 will be here
204E w, \ next movea.l a6,a0 \ store return stack ptr
2C4F w, \ movea.l a7,a6 \ save parm stack
9DFC w, 2328 , \ suba.l #12000,a6 \ allow stack to have 12000 bytes
2D08 w, \ move.l a0,-(a6) \ save old return stack ptr here
2D1F w, \ move.l (a7)+,-(a6) \ save return address here
48E63F1C , \ movem.l d2-d7/a3-a5,-(a6) \ save these registers, including a5
\ and a3
49faffe4 , \ lea data(pc),a4 \ point to a5 data area
2a5c w, \ movea.l (a4)+,a5 \ get a5
2654 w, \ movea.l (a4),a3 \ get a3, ptr to yerk base
2A0E w, \ move.l a6,d5 \ let ret stack have only 700
0485 w, 1f4 , \ subi.l #700,d5 \ and give method stack the rest
49FA0006 , \ lea 6(pc),a4 \ load a4 with ptr to routine
next,
\ PEXIT - This code is equally tricky as the above PSTART. This
\ restores the old A6 register and then jumps back to the
\ return location from which the word was called. This
\ code word will be invoked through the colon code, but
\ colon-code will never see it again.
Create P;s <[
4CDE38FC , \ movem.l (a6)+,d2-d7/a3-a5 \ restore a3 and a5 especially
205E w, \ movea.l (a6)+,a0
2C5E w, \ movea.l (a6)+,a6
4ED0 w, \ jmp (a0)
Decimal
' P;s nfa ' Pstart - docs 2* - -> pstartLen \ if documentation on, subtract 2.
\ build a word that looks like a Pascal procedure at its PFA
: :PROC
?exec create \ build hdr, cfa
' pstart here pstartLen allot pstartLen cMove
cflush \ flush caches on appropriate machines
]> ; \ enter compilation state
: ;PROC Compile P;s [Compile] <[ ; Immediate
\ don't assume proc word is always a :proc def..could be assembly
: initProc ( 'cproc -- ) >body dup 2+ @ $ 70726f63 = \ check for 'proc'
IF 6 + geta3a5 rot swap over ! 4+ ! ELSE drop THEN ;
: (initProcs) { theCfa arg -- } theCfa 6 + @ 'type proc = \ check for marker
IF theCfa initProc ." initProc: " theCfa >name id. cr THEN ; \ it's a procword, so init it
\ This word will initialize each procword in your program (at startup time)
: initProcs 'c (initProcs) 0 trav ;
\ **** STACK LAYOUT DURING PROCEDURE
\ |
\ method stack |
\ | <--- d5
\ ______________|
\ |
\ return stack | <--- a6
\ ______________|
\ |
\ data stack | <--- A7' = A7+4 (NEW DATA STACK)
\ | <---- a7
\ |
\ |
\ A6 |
\ (A7) RETURN |
\ D,A REGISTERS | <--- A6' = A7-3000 (NEW RETURN STACK)
\ |
\ |
\ | <--- D5' = A6'-300 (NEW METHODS STACK)
\